#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include "parsetree.h"
#include "humbug.h"


int yyparse();

extern FILE *yyin;
ParseTree *ProgramTree = NULL;


void Parse(char *FileName)
{
    // read the file
    yyin = fopen(FileName, "rt");
    if (yyin == NULL)
        Barf("can't open source file");

    // parse it
    if (yyparse() == 0)
        printf("done\n");
    else
        printf("parsing failed\n");

    // close
    fclose(yyin);
}


int main(int argc, char **argv)
{
    printf("humbug compiler v0.1\n");

    /* check parameters */
    if (argc < 2)
    {
        fprintf(stderr, "Format: humbug <file.c>\n");
        exit(1);
    }

    // parse the program
    Parse(argv[1]);

    if (ProgramTree != NULL)
        ProgramTree->Dump();
    else
        printf("ProgramTree is NULL\n");

    return 0;
}
